﻿using TjZheng.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using TjZheng.Framework;

namespace TjZheng.EasyUI
{
    public static partial class QueryExtension
    {
        public static MvcHtmlString QueryNumberBox(this HtmlHelper htmlHelper, string title, string name, QueryMethod objQueryMethod, QueryDataType objQueryDataType, object htmlAttributes = null, int precision = 0, double minValue = 0, double maxValue = 0, params string[] validTypes)
        {
            IDictionary<string, object> objHtmlAttributes = htmlAttributes.CreateValueDictionary();
            if (objHtmlAttributes.IsNull())
            {
                objHtmlAttributes = new Dictionary<string, object>();
            }
            List<string> dataOptionsList = new List<string>();
            if (validTypes.IsNoNull())
            {
                dataOptionsList.Add(string.Format("validType:[{0}]", validTypes.JoinComma()));
            }
            object data = null;
            if (objHtmlAttributes.TryGetValue("dataoptions", out data))
            {
                if (data.ToString().IsNoNull())
                {
                    dataOptionsList.Add(data.ToString());
                    objHtmlAttributes.Remove("dataoptions");
                }
            }
            if (precision > 0)
            {
                dataOptionsList.Add(string.Format("precision:{0}", precision));
            }
            if (minValue < maxValue)
            {
                dataOptionsList.Add(string.Format("min:{0}", minValue));
                dataOptionsList.Add(string.Format("max:{0}", maxValue));
            }
            if (dataOptionsList.IsNoNull())
            {
                objHtmlAttributes["data-options"] = dataOptionsList.JoinComma();
            }
            QueryTextBox objQueryTextBox = new QueryTextBox(name, QueryBoxType.NumberBox)
            {
                QueryTitle = title,
                QueryMethod = objQueryMethod,
                QueryDataType = objQueryDataType,
                HtmlAttributes = objHtmlAttributes
            };
            return htmlHelper.CreateQueryInfo(objQueryTextBox);
        }
        public static MvcHtmlString QueryNumberBox(this HtmlHelper htmlHelper, string title, string name, object htmlAttributes = null, int precision = 0, double minValue = 0, double maxValue = 0, params string[] validTypes)
        {
            return htmlHelper.QueryNumberBox(title, name, QueryMethod.Equal, QueryDataType.Int, htmlAttributes, precision, minValue, maxValue, validTypes);
        }
    }
}
